<?php

class ProfileController extends Controller {
    var $name = 'Profile';
    var $uses = array('Users','Groups');

    function index() {
        $this->action = 'profile';
        $this->profile();
    }

    function profile($username = null) {
        if (empty($username)) {
            $username = ArlicleUser::username();
        }
        $pass_edit_status = 'style="display: none;"';
        $pass_view_status = '';
        $password_wrong_notice = '';
        if (!empty($this->data)) {
            $this->data['Users']['id'] = $this->Users->field('id', "username='$username'");
            if (!empty($this->data['Users']['password_alpha'])) {
                if ($this->data['Users']['password_alpha'] == $this->data['Users']['password_beta']) {
                    $this->data['Users']['password'] = md5($this->data['Users']['password_alpha']);
                    $this->header_notice = __('Password change done.');
                } else {
                    $pass_edit_status = '';
                    $pass_view_status = 'style="display: none;"';
                    $password_wrong_notice = __('Password is wrong!');
                }
            }
            $this->Users->save($this->data);
        }
        $this->set('pass_edit_status', $pass_edit_status);
        $this->set('pass_view_status', $pass_view_status);
        $this->set('password_wrong_notice', $password_wrong_notice);
        $userinfo = $this->Users->find("username='$username'", array('id', 'nickname', 'date_joined', 'email', 'url', 'icq', 'aim', 'yim', 'jabber', 'tell', '`group_id`'));
        $this->data['Users'] = get_object_vars($userinfo);
        $this->set('username', $username);
        $this->set('created_time', date('Y-m-d', $userinfo->date_joined));
        if ($userinfo->id == 1) {
            $group_title = $username . __(' is not in any group in this site , but he has all power, you can&#8217;t delete it.<br>It&#8217;s a better way that don&#8217;t use this account post.');
        } else {
            $group_title = $this->Groups->field('title',"id='$userinfo->group_id'");
        }
        $this->set('group_title', $group_title);
    }
}

?>
